﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace EntityFrameworks.Web.Core.Attributes
{
    /// <summary>
    /// 授权过滤器
    /// MVC模式下使用
    /// </summary>
    public class AuthorizationFilter : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            if (filterContext.RequestContext.HttpContext.Session["UserID"] == null)
                filterContext.Result = new RedirectToRouteResult("Default", new RouteValueDictionary { 
                { "Action", "LogOn" },
                { "Controller", "System" }, 
                { "returnUrl", HttpContext.Current.Request.Url.ToString() } });
        }
    }
}